package org.lex.ftp.ui.bookmark;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JSplitPane;

import org.lex.ftp.util.Resources;


public class HideAndShowButton extends JButton implements ActionListener {
	private Icon showIcon = null;
	private Icon hideIcon = null;
	private JSplitPane pane = null;
	private int dividerLocation = 0;
	private boolean hided = true;

	public HideAndShowButton(JSplitPane pane) {
		super();
		this.pane = pane;
		this.dividerLocation = pane.getWidth() / 2;
		this.showIcon = Resources.getIcon(Resources.SHOW_ICON);
		this.hideIcon = Resources.getIcon(Resources.HIDE_ICON);
		this.setIcon(showIcon);
		this.setPreferredSize(new Dimension(showIcon.getIconHeight() + 2, showIcon.getIconWidth() + 2));
		this.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e) {
		if (true == this.hided) {
			this.setIcon(this.hideIcon);
			this.pane.setDividerLocation(this.dividerLocation);
			this.hided = false;
		} else {
			this.setIcon(this.showIcon);
			this.dividerLocation = this.pane.getDividerLocation();
			this.pane.setDividerLocation(this.pane.getWidth());
			this.hided = true;
		}
	}
}
